package com.itheima.hkzfapi.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName 反射构建对象花销
 * @Description TODO
 * @Author Shinelon
 * @Date DATE 2021/8/11 16:56
 */
public class 反射构建对象花销 {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        long k = System.currentTimeMillis();
        Class  c = Person.class;
        List<Person> list = new ArrayList<>();
        Constructor con = c.getConstructor(String.class,String.class);
        for(int i=0;i<2000;i++) {
           list.add( (Person) con.newInstance("魏志威","18"));
        }
        list=null;
        System.gc();
        System.out.println(System.currentTimeMillis()-k);
    }

}
